/****************************************************/
/* Project Name:房间信息管理                             */
/* File Name:TdcRoomController            */
/* Date:2017年3月22日下午19:31:12            */
/* Description:房间信息的业务逻辑层控制器        */
/****************************************************/ 
package com.thinkgem.jeesite.modules.tdc.room.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.tdc.room.entity.TdcRoom;
import com.thinkgem.jeesite.modules.tdc.room.service.TdcRoomService;

/**
 * 房间信息Controller
 * @author 孙瑞曦
 * @version 2017-03-20
 */
@Controller
@RequestMapping(value = "${adminPath}/room/tdcRoom")
public class TdcRoomController extends BaseController {

	@Autowired
	private TdcRoomService tdcRoomService;

	@ModelAttribute
	public TdcRoom get(@RequestParam(required=false) String id) {
		TdcRoom entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tdcRoomService.get(id);
		}
		if (entity == null){
			entity = new TdcRoom();
		}
		return entity;
	}
	/**
	 * 更改所有房间的状态为“空闲中”
	 * @param tdcRoom
	 * @param request
	 * @param response
	 * @param model
	 * @return 返回到tdcRoomList.jsp页面 
	 */
	@RequiresPermissions("room:tdcRoom:view")
	@RequestMapping(value = {"resetAllStatus"})
	public String resetAllStatus(TdcRoom tdcRoom, HttpServletRequest request, HttpServletResponse response, Model model) {
		System.out.println("service 02");
		String message="重置成功！";
		boolean n=tdcRoomService.allStatusReset();
		if(n==true){
			model.addAttribute("message", message);
		}
		Page<TdcRoom> page = tdcRoomService.findPage(new Page<TdcRoom>(request, response), tdcRoom); 
		model.addAttribute("page", page);
		return "tdc/room/tdcRoomList";
	}

	/**
	 * list:(分类管理页面，获取所有的房间信息)
	 * @param tdcRoom 房间表实体类对象
	 * @param request 向服务器提交pagesize和pageNo的信息
	 * @param response 向客户端回应返回来的pagesize和pageno信息
	 * @param model 房间表实体类entity
	 * @return 返回到分类查询页面
	 */
	@RequiresPermissions("room:tdcRoom:view")
	@RequestMapping(value = {"list", ""})
	public String list(TdcRoom tdcRoom, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TdcRoom> page = tdcRoomService.findPage(new Page<TdcRoom>(request, response), tdcRoom); 
		model.addAttribute("page", page);
		return "tdc/room/tdcRoomList";
	}
	/**
	 * form:(房间信息录入)
	 * @param tdcRoom 房间表实体类对象
	 * @param model	房间表实体类entity
	 * @return	进入到基础信息录入页
	 */
	@RequiresPermissions("room:tdcRoom:view")
	@RequestMapping(value = "form")
	public String form(TdcRoom tdcRoom, Model model) {
		model.addAttribute("tdcRoom", tdcRoom);
		return "tdc/room/tdcRoomForm";
	}
	/**
	 *  save:(保存录入的法律信息)
	 * @param tdcRoom 房间表实体类对象
	 * @param model	房间表实体类entity
	 * @param redirectAttributes 保存成功后的提示信息
	 * @return 返回到list方法
	 */
	@RequiresPermissions("room:tdcRoom:edit")
	@RequestMapping(value = "save")
	public String save(TdcRoom tdcRoom, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tdcRoom)){
			return form(tdcRoom, model);
		}
		tdcRoomService.save(tdcRoom);
		addMessage(redirectAttributes, "保存房间信息成功");
		return "redirect:"+Global.getAdminPath()+"/room/tdcRoom/?repage";
	}
	/**
	 * delete:(在房间分类查询页面中,根据id删除房间信息)
	 * @param tdcRoom 房间实体类对象
	 * @param redirectAttributes 删除成功后的提示信息
	 * @return 返回到list方法
	 */
	@RequiresPermissions("room:tdcRoom:edit")
	@RequestMapping(value = "delete")
	public String delete(TdcRoom tdcRoom, RedirectAttributes redirectAttributes) {
		tdcRoomService.delete(tdcRoom);
		addMessage(redirectAttributes, "删除房间信息成功");
		return "redirect:"+Global.getAdminPath()+"/room/tdcRoom/?repage";
	}

}